package com.example.broadcastbestpractice;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.WindowManager;

public class ForceOfflineReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(final Context context, Intent intent) {
		
       AlertDialog.Builder alertdialogbuilder=new AlertDialog.Builder(context);
       alertdialogbuilder.setTitle("Warning");
       alertdialogbuilder.setMessage("You are forced to be offline.Please try to login again.");
       alertdialogbuilder.setCancelable(false);
       alertdialogbuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			ActivityCollector.finishAll();
			Intent intent=new Intent(context,LoginActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent);
		}
	});
       AlertDialog  alertdialog=alertdialogbuilder.create();
       alertdialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
       alertdialog.show();
	}

}
